package log

import (
	"WrStoreServer/log/dingding"
	"WrStoreServer/log/file"

	"github.com/sirupsen/logrus"
)

// ConfigLog 配置日志信息
func ConfigLog(path string) {
	// 新建一个写文件hook
	logrus.Info("path:", path)

	hook := file.NewHook(path)
	if hook == nil {
		logrus.WithField("file", path).Fatalln("New logrus hook err.")
		return
	}

	logrus.AddHook(hook)
}

// NewLogger 新建一个logger
func NewLogger(t string, param string, recver []string) (logger *logrus.Logger) {
	logger = logrus.New()
	logrus.SetLevel(logrus.TraceLevel)
	logrus.SetFormatter(&logrus.JSONFormatter{})
	logrus.SetReportCaller(true)
	if t == "dingding" {
		logger.Hooks.Add(&dingding.Hook{
			WebHook: param,
			Phones:  recver,
		})
	}

	return
}
